<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use GuzzleHttp\Client;

class DelCfgCmd extends Command{

    public $signature = 'cfg:del';

    public function handle()
    {
        $fileArr = $this->getDir(public_path('cfg'));
        foreach ($fileArr as $file){
           $createTime =  filectime($file);
           if($createTime + 5 * 60 < time()){
               log_daily('del_cfg')->info($file);
               unlink($file);
           }
        }
    }

    function getDir($path)
    {
        //判断目录是否为空
        if(!file_exists($path)) {
            return [];
        }
        $files = scandir($path);
        $fileItem = [];
        foreach($files as $v) {
            $newPath = $path .DIRECTORY_SEPARATOR . $v;
            if(is_dir($newPath) && $v != '.' && $v != '..') {
                $fileItem = array_merge($fileItem, $this->getDir($newPath));
            }else if(is_file($newPath)){
                $fileItem[] = $newPath;
            }
        }
        return $fileItem;
    }
}


